package com.chaoyong.higo.activity;

import org.json.JSONException;
import org.json.JSONObject;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebSettings.LayoutAlgorithm;
import android.webkit.WebView;
import android.widget.ImageButton;

import com.chaoyong.higo.R;
import com.chaoyong.higo.base.BaseActivity;
import com.chaoyong.higo.net.OApi;
import com.chaoyong.higo.utils.V;
import com.chaoyong.higo.utils.Values;
import com.chaoyong.higo.view.TitleView;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;

public class XieyiActivity extends BaseActivity {
	@Override
	public int layoutResID() {
		return R.layout.activity_imag_detail;
	}

	private TitleView imagdet_title;
	private Context context;
	private ImageButton imagedet_imgbt;
	private WebView imagdet_webView;
	private String detail;

	@Override
	public void findView() {
		imagdet_title = V.f(this, R.id.imagdet_title);
		imagdet_webView = V.f(this, R.id.imagdet_webView);
	}

	@SuppressLint("SetJavaScriptEnabled")
	@SuppressWarnings("deprecation")
	@Override
	public void init() {
		context = this;
		// detail=getIntent().getStringExtra("info");
		imagdet_title.setTitleText("注册协议", context.getResources().getColor(R.color.white));
		imagdet_title.setLeftImage(R.drawable.bd_wallet_action_bar_back_normal);
		
		imagdet_title.setBackgroundColor(Color.RED);
		imagdet_title.setonLeftClinck(new OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();
			}
		});

		WebSettings webSettings = imagdet_webView.getSettings();
		/*
		 * webSettings.setSupportZoom(true);
		 * 
		 * webSettings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
		 * webSettings.setDisplayZoomControls(true);
		 * 
		 * webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
		 * webSettings.setBuiltInZoomControls(true);
		 */
		// imagdet_webView.loadData(detail,"text/html;charset=UTF-8", null);
		webSettings.setJavaScriptEnabled(true);

		webSettings.setJavaScriptEnabled(true);
		webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
		webSettings.setAllowFileAccess(true);// 设置允许访问文件数据
		webSettings.setSupportZoom(true);
		webSettings.setBuiltInZoomControls(true);
		webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
		webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
		webSettings.setDomStorageEnabled(true);
		webSettings.setDatabaseEnabled(true);

		imagdet_webView.setWebChromeClient(new WebChromeClient());

		// imagdet_webView.loadUrl("file:///android_asset/notice.html");
		// imagdet_webView.loadUrl("http://www.sangedabuliu.com/rtxxieyi/notice.html");
		// imagdet_webView.loadUrl("http://qiaoyu.applinzi.com");
		// imagdet_webView.loadUrl("http://qiaoyu.applinzi.com/xieyi/");
		// imagdet_webView.loadUrl("file:///android_asset/agreement.html");

		/*
		 * WebSettings webSettings = imagdet_webView.getSettings();
		 * webSettings.setSavePassword(false);
		 * webSettings.setSaveFormData(false);
		 * webSettings.setDefaultTextEncodingName("UTF-8");
		 * webSettings.setSupportZoom(true);
		 * webSettings.setJavaScriptEnabled(true);
		 * webSettings.setDefaultFontSize(14);
		 * webSettings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
		 */ // 图片大小

		/*
		 * String web="<!DOCTYPE html><html><head>" +
		 * "<meta name="+"\""+"viewport"+"\"content="+"\""+"width=device-width"+
		 * "\""+"/>" + "<title>一元云筹</title>" + "<style>" + "img{" +
		 * "max-width:95%;" + "width:95%;" + "height:100%;" + "}" + "</style>" +
		 * "</head><body>"; String wei="</body></html>"; web+=detail; web+=wei;
		 * imagdet_webView.loadDataWithBaseURL(null,web .replace("&lt;",
		 * "<").replace("&gt;", "/>") .replace("&amp;", "&"),
		 * "text/html","UTF-8", null);
		 */
	}

	@Override
	public void onClick(View v) {

	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		HttpUtils utils = new HttpUtils();
		utils.send(HttpMethod.GET, Values.web + "/admin/appport/atri", new RequestCallBack<String>() {

			@Override
			public void onFailure(HttpException arg0, String arg1) {
				// TODO Auto-generated method stub
				showToast(arg1);
			}

			@Override
			public void onSuccess(ResponseInfo<String> arg0) {
				// TODO Auto-generated method stub
				String result = arg0.result;
				try {
					JSONObject jso = new JSONObject(result);
					imagdet_webView.loadData(jso.getString("content"), "text/html;charset=UTF-8", null);
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});

	}

}
